package com.luseen.myapplication.slice;

import com.luseen.luseenbottomnavigation.BottomNavigation.BottomNavigationItem;
import com.luseen.luseenbottomnavigation.BottomNavigation.BottomNavigationView;
import com.luseen.luseenbottomnavigation.BottomNavigation.OnBottomNavigationItemClickListener;
import com.luseen.myapplication.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.colors.RgbColor;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.Text;
import ohos.agp.text.Font;
import ohos.agp.utils.Color;
import ohos.agp.window.service.Window;

public class MainAbilitySlice extends AbilitySlice {
    private BottomNavigationView bottomNavigationView;
    private Text textView;
    private Button button;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        Window window = getWindow();
        RgbColor rgbColor = new RgbColor(48, 63, 159);
        window.setStatusBarColor(rgbColor.asArgbInt());
        window.setNavigationBarColor(Color.BLACK.getValue());
        textView = (Text) findComponentById(ResourceTable.Id_text);
        button = (Button) findComponentById(ResourceTable.Id_button);
        bottomNavigationView = (BottomNavigationView) findComponentById(
                ResourceTable.Id_bottomNavigation);

        int[] image = {ResourceTable.Graphic_microphone, ResourceTable.Graphic_love,
                ResourceTable.Graphic_book, ResourceTable.Graphic_github_circle};
        RgbColor[] color = {new RgbColor(0, 188, 212), new RgbColor(233, 30, 90),
                new RgbColor(255, 87, 34), new RgbColor(76, 175, 80)};
        int[] colors = {0xff2196F3, 0xff757575};
        if (bottomNavigationView != null) {
            bottomNavigationView.isWithText(false);
            bottomNavigationView.isColoredBackground(true);
            bottomNavigationView.setTextActiveSize(15);
            bottomNavigationView.setTextInactiveSize(12);
            bottomNavigationView.setFont(Font.DEFAULT);
            bottomNavigationView.setItemActiveColorWithoutColoredBackground(colors[0]);
        }

        BottomNavigationItem bottomNavigationItem = new BottomNavigationItem(
                "Record", color[0], image[0]);
        BottomNavigationItem bottomNavigationItem1 = new BottomNavigationItem(
                "Like", color[1], image[1]);
        BottomNavigationItem bottomNavigationItem2 = new BottomNavigationItem(
                "Books", color[2], image[2]);
        BottomNavigationItem bottomNavigationItem3 = new BottomNavigationItem(
                "GitHub", color[3], image[3]);

        bottomNavigationView.addTab(bottomNavigationItem);
        bottomNavigationView.addTab(bottomNavigationItem1);
        bottomNavigationView.addTab(bottomNavigationItem2);
        bottomNavigationView.addTab(bottomNavigationItem3);

        bottomNavigationView.setOnBottomNavigationItemClickListener(
                new OnBottomNavigationItemClickListener() {
            @Override
            public void onNavigationItemClick(int index) {
                switch (index) {
                    case 0:
                        textView.setText("Record");
                        break;
                    case 1:
                        textView.setText("Like");
                        break;
                    case 2:
                        textView.setText("Books");
                        break;
                    case 3:
                        textView.setText("GitHub");
                        break;
                }
            }
        });

        button.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {

                try {
                    bottomNavigationView.selectTab(2);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}

